home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5168 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: druid.borland.com!usenet
  2. From: pete@borland.com (Pete Becker)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: void main() and other atrocities!
  5. Date: 7 Feb 1996 23:46:59 GMT
  6. Organization: Borland International
  7. Message-ID: <4fbdlj$o4g@druid.borland.com>
  8. References: <4eduaj$1aq@grouper.Exis.Net> <4em17r$shq@jaxnet.jaxnet.com> <4emub9$1mo@fountain.mindlink.net> <4epplj$egf@host-3.cyberhighway.net> <4erjn2INN38b@keats.ugrad.cs.ubc.ca> <9602021300.AA04359@dxmint.cern.ch> <4f5vc2$qcj@cdn_news.telecom.com.au>
  9. NNTP-Posting-Host: pbecker.borland.com
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=ISO-8859-1
  12. X-Newsreader: WinVN 0.99.5
  13.  
  14. In article <4f5vc2$qcj@cdn_news.telecom.com.au>, 
  15. jolson@vprpmel1.telecom.com.au says...
  16. >
  17. >How about:
  18. >
  19. >int main (int argc, char **argv)
  20. >
  21. >I saw in the FAQ that a multi-dimentional array will not decay into a pointer 
  22. >to a pointer.  This main() is valid with my Sparcworks compiler so I would 
  23. >like to know if my compiler is supporting non-standard behavior or if argv is 
  24. >a pointer to an array of characters (meaning it can decay into a pointer to a 
  25. >pointer).
  26.  
  27. In almost all contexts, the name of an array decays into a pointer to the 
  28. first element of the array. The argv parameter is the name of an array of 
  29. pointers to char, not a pointer to an array of characters. Since it is the 
  30. name of an array, it can decay into a pointer, which is why you can treat it 
  31. as a pointer to a pointer. In C syntax:
  32.  
  33.     char *argv[];        /* argv is an array of pointers to char */
  34.     char (*not_argv)[]; /* not_argv is a pointer to an array of char */
  35.  
  36.     char **works_like_argv = argv;            /* OK */
  37.     char **doesnt_work_like_argv = not_argv;    /* not OK */
  38.  
  39. Since not_argv is not the name of an array, it does not decay into a pointer, 
  40. and the assignment in the last line is not legal.
  41.     -- Pete
  42.  
  43.